#include "participant.h"
#include "person.h"

#include <QAbstractItemModel>
#include <QStandardItem>
#include <QTextStream>

Participant::Participant(int bib, bool member, Person* person)
{
    mBib = bib;

    QTextStream(&mName) << person->firstName() << " " << person->lastName();

    mAge = person->age();
    mGender = person->gender();

    mOrigin = person->city();
    mMember = member;
    mHide = false;
}

Participant::Participant(int bib,
                         QString name,
                         int age,
                         Person::Gender gender,
                         QString origin,
                         bool member
                         ) :
    mBib(bib),
    mName(name),
    mAge(age),
    mGender(gender),
    mOrigin(origin),
    mMember(member),
    mHide(false)
{
}

Participant::~Participant()
{
}

int  Participant::bib()
{
    return mBib;
}

QString  Participant::name()
{
    return mName;
}

int  Participant::age()
{
    return mAge;
}

QString  Participant::genderStr()
{
    QString g("?");
    if (mGender == Person::Male)
        g = "Male";
    if (mGender == Person::Male)
        g = "Female";
    return g;
}

QString Participant::origin()
{
    return mOrigin;
}

bool Participant::member()
{
    return mMember;
}

bool Participant::hidden()
{
    return mHide;
}

Person::Gender Participant::gender()
{
    return mGender;
}

QList<QStandardItem*>
Participant::standardItemList()
{
    QString bibNumber;
    bibNumber.sprintf("#%d", bib());

    QString ageString;
    ageString.sprintf("%d", age());

    QString genderString;
    if (gender() == Person::Male)
        genderString = "Male";
    else if (gender() == Person::Female)
        genderString = "Female";
    else
        genderString = "Not specified";

    QStandardItem *bibItem = new QStandardItem(bibNumber);
    //bibItem->setData(QVariant(this));

    QStandardItem *nameItem = new QStandardItem(name().toUpper());
    QStandardItem *ageItem = new QStandardItem(ageString);
    QStandardItem *genderItem = new QStandardItem(genderString);
    QStandardItem *originItem = new QStandardItem(origin().toUpper());

    QList<QStandardItem*> items; items << bibItem << nameItem << ageItem << genderItem << originItem;
    return items;
}
